// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_float_from_decimal32_9_4") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_float_from_decimal32_9_4_0_nullable;"
    sql "create table test_cast_to_float_from_decimal32_9_4_0_nullable(f1 int, f2 decimalv3(9, 4)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal32_9_4_0_nullable values (0, "0.0000"),(1, "0.0000"),(2, "0.0001"),(3, "-0.0001"),(4, "0.0009"),(5, "-0.0009"),(6, "0.0999"),(7, "-0.0999"),(8, "0.9000"),(9, "-0.9000"),(10, "0.9001"),(11, "-0.9001"),(12, "0.9998"),(13, "-0.9998"),(14, "0.9999"),(15, "-0.9999"),(16, "1.0000"),(17, "-1.0000"),(18, "1.0001"),(19, "-1.0001"),
      (20, "1.0009"),(21, "-1.0009"),(22, "1.0999"),(23, "-1.0999"),(24, "1.9000"),(25, "-1.9000"),(26, "1.9001"),(27, "-1.9001"),(28, "1.9998"),(29, "-1.9998"),(30, "1.9999"),(31, "-1.9999"),(32, "9.0000"),(33, "-9.0000"),(34, "9.0001"),(35, "-9.0001"),(36, "9.0009"),(37, "-9.0009"),(38, "9.0999"),(39, "-9.0999"),
      (40, "9.9000"),(41, "-9.9000"),(42, "9.9001"),(43, "-9.9001"),(44, "9.9998"),(45, "-9.9998"),(46, "9.9999"),(47, "-9.9999"),(48, "9999.0000"),(49, "-9999.0000"),(50, "9999.0001"),(51, "-9999.0001"),(52, "9999.0009"),(53, "-9999.0009"),(54, "9999.0999"),(55, "-9999.0999"),(56, "9999.9000"),(57, "-9999.9000"),(58, "9999.9001"),(59, "-9999.9001"),
      (60, "9999.9998"),(61, "-9999.9998"),(62, "9999.9999"),(63, "-9999.9999"),(64, "90000.0000"),(65, "-90000.0000"),(66, "90000.0001"),(67, "-90000.0001"),(68, "90000.0009"),(69, "-90000.0009"),(70, "90000.0999"),(71, "-90000.0999"),(72, "90000.9000"),(73, "-90000.9000"),(74, "90000.9001"),(75, "-90000.9001"),(76, "90000.9998"),(77, "-90000.9998"),(78, "90000.9999"),(79, "-90000.9999"),
      (80, "90001.0000"),(81, "-90001.0000"),(82, "90001.0001"),(83, "-90001.0001"),(84, "90001.0009"),(85, "-90001.0009"),(86, "90001.0999"),(87, "-90001.0999"),(88, "90001.9000"),(89, "-90001.9000"),(90, "90001.9001"),(91, "-90001.9001"),(92, "90001.9998"),(93, "-90001.9998"),(94, "90001.9999"),(95, "-90001.9999"),(96, "99998.0000"),(97, "-99998.0000"),(98, "99998.0001"),(99, "-99998.0001"),
      (100, "99998.0009"),(101, "-99998.0009"),(102, "99998.0999"),(103, "-99998.0999"),(104, "99998.9000"),(105, "-99998.9000"),(106, "99998.9001"),(107, "-99998.9001"),(108, "99998.9998"),(109, "-99998.9998"),(110, "99998.9999"),(111, "-99998.9999"),(112, "99999.0000"),(113, "-99999.0000"),(114, "99999.0001"),(115, "-99999.0001"),(116, "99999.0009"),(117, "-99999.0009"),(118, "99999.0999"),(119, "-99999.0999"),
      (120, "99999.9000"),(121, "-99999.9000"),(122, "99999.9001"),(123, "-99999.9001"),(124, "99999.9998"),(125, "-99999.9998"),(126, "99999.9999"),(127, "-99999.9999")
      ,(128, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal32_9_4_0_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal32_9_4_0_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal32_9_4_0_not_nullable;"
    sql "create table test_cast_to_float_from_decimal32_9_4_0_not_nullable(f1 int, f2 decimalv3(9, 4)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal32_9_4_0_not_nullable values (0, "0.0000"),(1, "0.0000"),(2, "0.0001"),(3, "-0.0001"),(4, "0.0009"),(5, "-0.0009"),(6, "0.0999"),(7, "-0.0999"),(8, "0.9000"),(9, "-0.9000"),(10, "0.9001"),(11, "-0.9001"),(12, "0.9998"),(13, "-0.9998"),(14, "0.9999"),(15, "-0.9999"),(16, "1.0000"),(17, "-1.0000"),(18, "1.0001"),(19, "-1.0001"),
      (20, "1.0009"),(21, "-1.0009"),(22, "1.0999"),(23, "-1.0999"),(24, "1.9000"),(25, "-1.9000"),(26, "1.9001"),(27, "-1.9001"),(28, "1.9998"),(29, "-1.9998"),(30, "1.9999"),(31, "-1.9999"),(32, "9.0000"),(33, "-9.0000"),(34, "9.0001"),(35, "-9.0001"),(36, "9.0009"),(37, "-9.0009"),(38, "9.0999"),(39, "-9.0999"),
      (40, "9.9000"),(41, "-9.9000"),(42, "9.9001"),(43, "-9.9001"),(44, "9.9998"),(45, "-9.9998"),(46, "9.9999"),(47, "-9.9999"),(48, "9999.0000"),(49, "-9999.0000"),(50, "9999.0001"),(51, "-9999.0001"),(52, "9999.0009"),(53, "-9999.0009"),(54, "9999.0999"),(55, "-9999.0999"),(56, "9999.9000"),(57, "-9999.9000"),(58, "9999.9001"),(59, "-9999.9001"),
      (60, "9999.9998"),(61, "-9999.9998"),(62, "9999.9999"),(63, "-9999.9999"),(64, "90000.0000"),(65, "-90000.0000"),(66, "90000.0001"),(67, "-90000.0001"),(68, "90000.0009"),(69, "-90000.0009"),(70, "90000.0999"),(71, "-90000.0999"),(72, "90000.9000"),(73, "-90000.9000"),(74, "90000.9001"),(75, "-90000.9001"),(76, "90000.9998"),(77, "-90000.9998"),(78, "90000.9999"),(79, "-90000.9999"),
      (80, "90001.0000"),(81, "-90001.0000"),(82, "90001.0001"),(83, "-90001.0001"),(84, "90001.0009"),(85, "-90001.0009"),(86, "90001.0999"),(87, "-90001.0999"),(88, "90001.9000"),(89, "-90001.9000"),(90, "90001.9001"),(91, "-90001.9001"),(92, "90001.9998"),(93, "-90001.9998"),(94, "90001.9999"),(95, "-90001.9999"),(96, "99998.0000"),(97, "-99998.0000"),(98, "99998.0001"),(99, "-99998.0001"),
      (100, "99998.0009"),(101, "-99998.0009"),(102, "99998.0999"),(103, "-99998.0999"),(104, "99998.9000"),(105, "-99998.9000"),(106, "99998.9001"),(107, "-99998.9001"),(108, "99998.9998"),(109, "-99998.9998"),(110, "99998.9999"),(111, "-99998.9999"),(112, "99999.0000"),(113, "-99999.0000"),(114, "99999.0001"),(115, "-99999.0001"),(116, "99999.0009"),(117, "-99999.0009"),(118, "99999.0999"),(119, "-99999.0999"),
      (120, "99999.9000"),(121, "-99999.9000"),(122, "99999.9001"),(123, "-99999.9001"),(124, "99999.9998"),(125, "-99999.9998"),(126, "99999.9999"),(127, "-99999.9999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal32_9_4_0_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal32_9_4_0_not_nullable order by 1;'

}